package com.ruoyi.asset.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.core.domain.Ztree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.asset.mapper.AstStoreroomMapper;
import com.ruoyi.asset.domain.AstStoreroom;
import com.ruoyi.asset.service.IAstStoreroomService;
import com.ruoyi.common.core.text.Convert;

/**
 * 库房管理Service业务层处理
 * 
 * @author xunzhe
 * @date 2024-06-17
 */
@Service
public class AstStoreroomServiceImpl implements IAstStoreroomService 
{
    @Autowired
    private AstStoreroomMapper astStoreroomMapper;

    /**
     * 查询库房管理
     * 
     * @param storeroomId 库房管理主键
     * @return 库房管理
     */
    @Override
    public AstStoreroom selectAstStoreroomByStoreroomId(Long storeroomId)
    {
        return astStoreroomMapper.selectAstStoreroomByStoreroomId(storeroomId);
    }

    /**
     * 查询库房管理列表
     * 
     * @param astStoreroom 库房管理
     * @return 库房管理
     */
    @Override
    public List<AstStoreroom> selectAstStoreroomList(AstStoreroom astStoreroom)
    {
        return astStoreroomMapper.selectAstStoreroomList(astStoreroom);
    }

    /**
     * 新增库房管理
     * 
     * @param astStoreroom 库房管理
     * @return 结果
     */
    @Override
    public int insertAstStoreroom(AstStoreroom astStoreroom)
    {
        return astStoreroomMapper.insertAstStoreroom(astStoreroom);
    }

    /**
     * 修改库房管理
     * 
     * @param astStoreroom 库房管理
     * @return 结果
     */
    @Override
    public int updateAstStoreroom(AstStoreroom astStoreroom)
    {
        return astStoreroomMapper.updateAstStoreroom(astStoreroom);
    }

    /**
     * 批量删除库房管理
     * 
     * @param storeroomIds 需要删除的库房管理主键
     * @return 结果
     */
    @Override
    public int deleteAstStoreroomByStoreroomIds(String storeroomIds)
    {
        return astStoreroomMapper.deleteAstStoreroomByStoreroomIds(Convert.toStrArray(storeroomIds));
    }

    /**
     * 删除库房管理信息
     * 
     * @param storeroomId 库房管理主键
     * @return 结果
     */
    @Override
    public int deleteAstStoreroomByStoreroomId(Long storeroomId)
    {
        return astStoreroomMapper.deleteAstStoreroomByStoreroomId(storeroomId);
    }

    /**
     * 查询库房管理树列表
     * 
     * @return 所有库房管理信息
     */
    @Override
    public List<Ztree> selectAstStoreroomTree()
    {
        List<AstStoreroom> astStoreroomList = astStoreroomMapper.selectAstStoreroomList(new AstStoreroom());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (AstStoreroom astStoreroom : astStoreroomList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(astStoreroom.getStoreroomId());
            ztree.setpId(astStoreroom.getParentId());
            ztree.setName(astStoreroom.getStoreroomName());
            ztree.setTitle(astStoreroom.getStoreroomName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
